package com.example.leetdemo.plan1;

public class Sword019 {

    public boolean validPalindrome(String s) {
        if (s.length() <= 2) {
            return true;
        }
        int p = 0, q = s.length() - 1;
        while (p < q) {
            if (s.charAt(p) == s.charAt(q)) {
                p++;
                q--;
            } else {
                StringBuilder builder = new StringBuilder();
                builder.append(s,p + 1, q + 1);
                String a = builder.toString();
                if (a.equals(builder.reverse().toString())) {
                    return true;
                }
                builder = new StringBuilder();
                builder.append(s, p, q);
                a = builder.toString();
                if (a.equals(builder.reverse().toString())) {
                    return true;
                }
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Sword019 sword019 = new Sword019();
        System.err.println(sword019.validPalindrome("aba"));
    }
}
